<?php

namespace Mobile\Controller;

/**
 * Description of 客栈相关控制器接口
 * 
 * @author songanwei
 * @date 2016-1-22
 */
class HotelController extends ParentController {

    protected function _initialize() {
        if (!in_array(ACTION_NAME, array('getRemindList'))) {
            parent::_initialize();
        }
        $this->validateUtil = new \Org\Util\Validate();
    }

    /**
     * @description 获取用户相关客栈数据
     * @modify songanwei 2016-01-22
     */
    public function items() {
        $params = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
        );
        $this->ajaxValidateReturn($this->validateUtil, $params, $validateRule);
        $userId = $params['userId'];
        $token = $params['token'];

        //检查token
        $this->checkMobileToken($userId, $token);
        //获取客栈数据
        $hotelLogic = A('Common/Hotel', 'Logic');
        $hotels = $hotelLogic->getHotelByUser($userId);
        
        $hotelIds = array_column($hotels, 'hotelentity_id');
        
        $hotelAppModel = D('HotelApp');
        $hotelAppInfos = $hotelAppModel->getList($hotelIds);
        $hotelAppInfos = getArrayValueAsIndex($hotelAppInfos, 'hotelentity_id');            
        $hourRooomModel = D('HourRoomInit');

        $currencyLogic = A('Common/Currency', 'Logic');
        //获取区号时区数据
        $HotelLogic = A('Common/Hotel', 'Logic');
        $universalTimeData = $HotelLogic->universalTimeList();
        $data = array();
        //获取客栈数据
        foreach ($hotels as $hotel) {            
            if ($hotel['status'] == 1) {
                continue;
            }
            $appStatus = false;
            if(isset($hotelAppInfos[$hotel['hotelentity_id']])){            
                $hotelAppInfo = $hotelAppInfos[$hotel['hotelentity_id']];
                if($hotelAppInfo['status']==1 && time()<strtotime($hotelAppInfo['enddate'])){
                    $appStatus = true;
                }
            }
            $hourRoom = $hourRooomModel->getInfo($hotel['hotelentity_id']);
             // 获取默认货币符号
            $hotelDefaultCurrency = $currencyLogic->takeHotelCurrency($hotel['hotelentity_id'], true);
            $hotelDefaultSymbol = !empty($hotelDefaultCurrency) ? $hotelDefaultCurrency[0]['symbol'] : '¥';
            $currencyId = !empty($hotelDefaultCurrency) ? $hotelDefaultCurrency[0]['currencyId'] : 8;

            $universalTimeData = getArrayValueAsIndex($universalTimeData, 'universalTimeId');
            $areaCode = $universalTimeData[$hotel['universaltime_id']]['areaCode'];
            $data[] = array(
                'hotelId' => $hotel['hotelentity_id'],
                'hotelName' => $hotel['name'],
                'role' => $hotel['role'],
                'appStatus' => $appStatus,
                'hourRoomInit' => empty($hourRoom) ? 0 : 1,
                'hourRoomCheckinTime' => isset($hourRoom['checkintime']) ? $hourRoom['checkintime'] : '',
                'hourRoomCheckoutTime' => isset($hourRoom['checkouttime']) ? $hourRoom['checkouttime'] : '',
                'areaCode' => $areaCode,
                'symbol' => $hotelDefaultSymbol,
                'currencyId' => $currencyId,
            );
        }

        returnJson(200, 200, $data);
    }

    /**
     * @description 获取客栈资源，包括客栈渠道数据、客栈支付方式
     * @modify songanwei 2016-01-23
     */
    public function resource() {
        $params = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
            'hotel' => 'notnull,notempty,id',
        );
        $this->ajaxValidateReturn($this->validateUtil, $params, $validateRule);
        $userId = $params['userId'];
        $token = $params['token'];
        $hotelId = $params['hotel'];

        //检验token
        $this->checkMobileToken($userId, $token);
        // 渠道和支付方式
        $hotelLogic = A('Common/Hotel', 'Logic');
        $hotelChannels = $hotelLogic->getHotelChannel($hotelId, false);
        $hotelPays = $hotelLogic->getHotelPay($hotelId, false);

        // 记一笔项目数据
        $hotelNoteData = $hotelLogic->getHotelNote($hotelId, false, null, true);
        // 其他消费项目数据
        $otherCostData = $hotelLogic->getHotelOtherCost($hotelId);

        // 获取系统货币
        $currencyLogic = A('Common/Currency', 'Logic');
        $currency = $currencyLogic->getBpCurrency();
        $data['currency'] = $currency;

        $data['channels'] = $data['pays'] = $data['noteInCome'] = $data['noteOutCome'] = $data['otherCost'] = array();
        foreach ($hotelChannels as $hotelChannel) {
            $data['channels'][] = array(
                'channelId' => $hotelChannel['id'],
                'name' => $hotelChannel['name']
            );
        }
        foreach ($hotelPays as $hotelPay) {
            $data['pays'][] = array(
                'payId' => $hotelPay['id'],
                'name' => $hotelPay['name']
            );
        }
        foreach ($hotelNoteData['income'] as $note) {
            $data['noteInCome'][] = array(
                'noteId' => $note['id'],
                'name' => $note['name']
            );
        }
        foreach ($hotelNoteData['outcome'] as $note) {
            $data['noteOutCome'][] = array(
                'noteId' => $note['id'],
                'name' => $note['name']
            );
        }
        foreach ($otherCostData as $cost) {
            $data['otherCost'][] = array(
                'costId' => $cost['id'],
                'name' => $cost['name']
            );
        }

        returnJson(200, 200, $data);
    }

    /**
     * 保存我的客栈信息
     * @modify wenhui 2016-11-07    创建
     * @modify wenhui 2017-05-04 增加国际手机检验
     */
    public function save() {
        $param = I('post.');

        // v2.0.11的参数校验 支持国际号码校验
        $version = getVersion(array('2.0.11'));
        if ($version >= '2.0.11') {
            $validateRule = array(
                'userId' => 'notnull,notempty,id',
                'hotel' => 'notnull,notempty,id',
                'token' => 'notnull,notempty',
                'name' => 'notnull,notempty,nameLength20',
                'contact' => 'notnull,notempty,nameLength20',
                'mobile' => 'notnull,notempty',
                'address' => 'notnull,notempty,nameLength50',
                'longtitude' => 'notempty,decimal9_6',
                'latitude' => 'notempty,decimal9_6',
                'description' => 'notempty,nameLength255',
                'orderTimeout' => 'notempty,orderTimeout',
                'telephone' => 'notempty,nameLength15',
                'wechat' => 'notempty,nameLength20',
                'hotline' => 'notempty,nameLength15',
            );
            $areaCode = I('post.areaCode', '86', 'string');
            $this->ajaxValidateReturn($this->validateUtil, $param['mobile'], 'globalMobile',
                        array('globalMobile' => array('function', 'checkGlobalMobile,' . $areaCode, '403,130,error'),
                    ));
        } else {
            $validateRule = array(
                'userId' => 'notnull,notempty,id',
                'hotel' => 'notnull,notempty,id',
                'token' => 'notnull,notempty',
                'name' => 'notnull,notempty,nameLength20',
                'contact' => 'notnull,notempty,nameLength20',
                'mobile' => 'notnull,notempty,mobile',
                'address' => 'notnull,notempty,nameLength50',
                'longtitude' => 'notempty,decimal9_6',
                'latitude' => 'notempty,decimal9_6',
                'description' => 'notempty,nameLength255',
                'orderTimeout' => 'notempty,orderTimeout',
                'telephone' => 'notempty,nameLength15',
                'wechat' => 'notempty,nameLength20',
                'hotline' => 'notempty,nameLength15',
            );
        }

        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (! $validatePass) {
            return;
        }
        $userId = $param['userId'];
        $token = $param['token'];
        $hotelId = $param['hotel'];
        $mobile = isset($param['mobile']) ? $param['mobile'] : null;
        $areaCode = isset($areaCode) ? $areaCode : '86';
        
        // 检验token
        $this->checkMobileToken($userId, $token);
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        // 校验是否已经开通
        $isEnable = $hotelBookLogic->checkEnable($hotelId); 
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        $name = null;
        $contact = isset($param['contact']) ? $param['contact'] : null;
        $address = isset($param['address']) ? $param['address'] : null;
        $description = isset($param['description']) ? $param['description'] : '';
        $orderTimeout = isset($param['orderTimeout']) ? $param['orderTimeout'] : null;
        $telephone = isset($param['telephone']) ? $param['telephone'] : '';
        $wechat = isset($param['wechat']) ? $param['wechat'] : '';
        $hotline = isset($param['hotline']) ? $param['hotline'] : '';
        $longtitude = isset($param['longtitude']) ? $param['longtitude'] : null;
        $latitude = isset($param['latitude']) ? $param['latitude'] : null;
        
        $saveResult = $hotelBookLogic->saveDetail($hotelId, null, $name, $description, $contact, $mobile, $telephone, $wechat, $address, $longtitude, $latitude, $orderTimeout, $hotline, null, $areaCode);
        if (empty($saveResult)) {
            return;
        }

        $hotelAuthModel = D('HotelAuth');
        $hotelAuthInfo = $hotelAuthModel->getInfo($hotelId);
        if(!empty($hotelAuthInfo)){
            if($hotelAuthInfo['contact']!=$param['contact'] || $hotelAuthInfo['telephone']!=$param['mobile'] || $hotelAuthInfo['address']!=$param['address']){
                //丢掉认证标志
                $where = array(
                    'hotelentity_id' => $hotelId
                );
                $data = array(
                    'certified' => 0,
                );
                $hotelDetailModel = D('HotelDetail');
                $hotelDetailModel->where($where)->save($data);
                //变为未申请
                $data = array(
                    'status' => 0,
                );
                $hotelAuthModel->where($where)->save($data);
            }
        }
        
        returnJson(200, 200);
    }

    /**
     * 保存设施信息
     * @modify wenhui 2016-11-08    创建
     */
    public function saveFacilityInfo() {
        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'hotel' => 'notnull,notempty,id',
            'token' => 'notnull,notempty', 
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (!$validatePass) {
            return;
        }
        if (isset($param['facility'])) {
            $facility = $param['facility'];
            if ($facility != '') {
                $validatePass = $this->ajaxValidateReturn($this->validateUtil, $facility, 'concatId');
                if (!$validatePass) {
                    return;
                }
                $facility = explode(',', $facility);
            } else {
                $facility = array();
            }
        } else {
            $facility = null;
        }
        $userId = $param['userId'];
        $token = $param['token'];
        $hotelId = $param['hotel'];

        //检验token
        $this->checkMobileToken($userId, $token);      
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        // 校验是否已经开通
        $isEnable = $hotelBookLogic->checkEnable($hotelId); 
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        $saveResult = $hotelBookLogic->saveDetail($hotelId, $facility, null, null, null, null, null, null, null, null, null, null);
        if (empty($saveResult)) {
            return;
        }
        returnJson(200, 200);
    }

    /**
     * 获取客栈信息
     * @modify wenhui 2016-11-08    创建
     */
    public function getHotelInfo() {
        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'hotel' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
        );

        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        $hotelId = $param['hotel'];
        // 校验是否已经开通
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }
        
        // 处理数据
        $hotelDetail = $hotelBookLogic->getInfo($hotelId);
        unset($hotelDetail['enable']);
        $hotelDetail['orderTimeout'] = $hotelDetail['ordertimeout'];
        $hotelDetail['areaCode'] = $hotelDetail['areacode'];
        unset($hotelDetail['areacode']);
        unset($hotelDetail['ordertimeout']);
        unset($hotelDetail['specialimageurl']);
        unset($hotelDetail['coverimageurl']);
        unset($hotelDetail['special']);
        unset($hotelDetail['specialTag']);
        unset($hotelDetail['gallery']);
        unset($hotelDetail['facility']);
        unset($hotelDetail['hotelentity_id']);
        
        // 获取认证信息
        $hotelAuthModel = D('HotelAuth');
        $hotelAuthInfo = $hotelAuthModel->getInfo($hotelId);       
        if(empty($hotelAuthInfo)){
            $hotelDetail['authInfo'] = array(
                'hotelname' => '',
                'contact' => '',
                'telephone' => '',
                'address' => '',
                'status' => 0,
            );
        }
        else {      
            $status = $hotelAuthInfo['status'];
            if($status=='2' && (empty($hotelDetail['certified'])||time()>strtotime($hotelDetail['certifiedenddate']))){
                $status = '4';
            }
            $hotelDetail['authInfo'] = array(
            	'hotelname' => $hotelAuthInfo['hotelname'],
            	'contact' => $hotelAuthInfo['contact'],
            	'telephone' => $hotelAuthInfo['telephone'],
            	'address' => $hotelAuthInfo['address'],
            	'status' => $status,
            );
        }

        returnJson(200, 200, $hotelDetail);
    }

    /**
     * 获取设施信息
     * @modify wenhui 2016-11-08    创建
     */
    public function getFacilityInfo() {
        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'hotel' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
        );

        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        $hotelId = $param['hotel'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        // 校验是否已经开通
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        $hotelDetail = $hotelBookLogic->getInfo($hotelId);
        // 处理数据
        unset($hotelDetail['enable']);
        unset($hotelDetail['ordertimeout']);
        unset($hotelDetail['specialimageurl']);
        unset($hotelDetail['coverimageurl']);
        unset($hotelDetail['special']);
        unset($hotelDetail['specialTag']);
        unset($hotelDetail['gallery']);
        unset($hotelDetail['longtitude']);
        unset($hotelDetail['latitude']);
        unset($hotelDetail['name']);
        unset($hotelDetail['description']);
        unset($hotelDetail['contact']);
        unset($hotelDetail['mobile']);
        unset($hotelDetail['telephone']);
        unset($hotelDetail['wechat']);
        unset($hotelDetail['address']);
        unset($hotelDetail['hotelentity_id']);
        unset($hotelDetail['bookmode']);

        returnJson(200, 200, $hotelDetail);
    }

    /**
     * 获取客栈畅联代收/商家自收支付信息
     * @modify trainyao 2016-07-11    创建
     * @modify wenhui 2016-12-07    校验token
     */
    public function payInfo() {
        
        $mobile_version = C('MOBILE_VERSION');
        if($_SERVER['HTTP_V']<$mobile_version['multi_pay_type']){
            returnJson(403, 999);
            return;
        }
        
        $param = I('post.');

        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        // 校验token
        $userId = $param['userId'];
        $token = $param['token'];
        $this->checkMobileToken($userId, $token);

        // 校验客栈是否过期,是否禁用
        $hotelId = $param['hotel'];
        $hotelLogic = A('Common/Hotel', 'Logic');
        $result = $hotelLogic->checkHotelActive($hotelId);
        if ($result == false) {
            returnJson(403, 408);
            return;
        }
        $result = $hotelLogic->checkHotelStatus($hotelId);
        if ($result == false) {
            returnJson(403, 401);
            return;
        }

        // 校验是否有操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $hasRight = $adminAuthorityLogic->check($hotelId);
        if (!$hasRight) {
            returnJson(403, 202);
            return;
        }

        // 保存支付类型
        $hotelPayLogic = A('Common/HotelPay', 'Logic');
        $returnData = $hotelPayLogic->getPartnerPayInfo($hotelId);        

        // 支付功能开通情况
        $payUsable = array(
                'uclbrtAlipayEnable'=>false,
                'uclbrtWechatEnable'=>false,
                'hotelAlipayEnable'=>false,
                'hotelWechatEnable'=>false,
        );
        $hotelPayUsableModel = D('HotelPayUsable');
        $hotelPayUsableInfo = $hotelPayUsableModel->getInfo($hotelId);
        if(!empty($hotelPayUsableInfo)){
            $payUsable = array(
                    'uclbrtAlipayEnable'=>!empty($hotelPayUsableInfo['uclbrtalipayenable']) && time()<strtotime($hotelPayUsableInfo['uclbrtalipayenddate']),
                    'uclbrtWechatEnable'=>!empty($hotelPayUsableInfo['uclbrtwechatenable']) && time()<strtotime($hotelPayUsableInfo['uclbrtwechatenddate']),
                    'hotelAlipayEnable'=>!empty($hotelPayUsableInfo['hotelalipayenable']) && time()<strtotime($hotelPayUsableInfo['hotelalipayenddate']),
                    'hotelWechatEnable'=>!empty($hotelPayUsableInfo['hotelwechatenable']) && time()<strtotime($hotelPayUsableInfo['hotelwechatenddata']),
            );
        }
        $returnData['payUsable'] = $payUsable;

        returnJson(200, 200, $returnData);
    }

    /**
     * 保存客栈支付信息
     * @modify trainyao 2016-07-11    创建
     * @modify wenhui 2016-12-07  校验token
     * @modify wenhui 2017-02-06  添加版本判断
     */
    public function savePayInfo() {
        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        // json转换
        $wechat = json_decode(stripslashes(htmlspecialchars_decode($param['wechat'])), true);
        $ali = json_decode(stripslashes(htmlspecialchars_decode($param['ali'])), true);

        $wechatPayInfo = null;
        $aliPayInfo = null;
        if (isset($wechat)) {
            $wechatPayInfo = $wechat;
            if (!isset($wechatPayInfo['mpverify'])) {
                returnJson(403, 205);
            }

            $validateRule = array(
                'appid' => 'notnull,notempty,length32',
                'appsecret' => 'notnull,notempty,length32',
                'mchid' => 'notnull,notempty,length32',
                'mchkey' => 'notnull,notempty,nameLength50',
                'mpverify' => 'notnull,notempty,mpverify,nameLength50',
            );

            $validatePass = $this->ajaxValidateReturn($this->validateUtil, $wechatPayInfo, $validateRule, array(
                'length32' => array('mblength', '0,32,utf-8', '403,213,error'),
                'mpverify' => array('regex', '/^MP_verify_[0-9A-Za-z]+(\.txt)?$/', '403,204,error'),
            ));
            if (empty($validatePass)) {
                return;
            }
        }
        if (isset($ali)) {
            $aliPayInfo = $ali;
            $validateRule = array(
                'account' => 'notnull,notempty,nameLength50',
                'pid' => 'notnull,notempty,length40',
                'key' => 'notnull,notempty,length40',
            );
            $validatePass = $this->ajaxValidateReturn($this->validateUtil, $aliPayInfo, $validateRule, array(
                'length40' => array('mblength', '0,40,utf-8', '403,213,error'),
            ));
            if (empty($validatePass)) {
                return;
            }
        }

        // 校验token
        $userId = $param['userId'];
        $token = $param['token'];
        $this->checkMobileToken($userId, $token);

        // 校验客栈是否过期,是否禁用
        $hotelId = $param['hotel'];
        $hotelLogic = A('Common/Hotel', 'Logic');
        $result = $hotelLogic->checkHotelActive($hotelId);
        if ($result == false) {
            returnJson(403, 408);
            return;
        }
        $result = $hotelLogic->checkHotelStatus($hotelId);
        if ($result == false) {
            returnJson(403, 401);
            return;
        }

        // 校验是否有操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $hasRight = $adminAuthorityLogic->check($hotelId);
        if (!$hasRight) {
            returnJson(403, 202);
            return;
        }

        // 保存支付类型
        $hotelPayLogic = A('Common/HotelPay', 'Logic');
        try {
            $hotelPayLogic->savePayInfo($hotelId, $wechatPayInfo, $aliPayInfo);
        } catch (\Exception $e) {
            returnJson($e->getMessage());
            return;
        }

        returnJson(200, 200);
    }

    /**
     * 保存客栈支付类型
     * @modify trainyao 2016-07-11    创建
     * @modify wenhui 2016-12-07    校验token
     */
    public function togglePayType() {
        
        $mobile_version = C('MOBILE_VERSION');
        if($_SERVER['HTTP_V']<$mobile_version['multi_pay_type']){
            returnJson(403, 999);
            return;
        }
        
        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
            'type' => 'notnull,notempty',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        
        $type = $param['type'];
        $mobile_version = C('MOBILE_VERSION');
        if (!in_array($type, array('0','1','2','16','32','3','33','18','48','64','65','66','67','80','82','96','97','112')))
        {            
            returnJson(403, 213);
            return;
        }

        $hotelId = $param['hotel'];

        // 是否是义卖客栈 只能畅联代收  可以开启会员卡支付
        $result = $this->checkUsageHotel($hotelId);
        if ($result['isFreeHotel'] === true) {
            if(!in_array($type, array('0','1','2','3','64','65','66','67'))){
                returnJson(403, 422);
                return;
            }
        }

        // 校验token
        $userId = $param['userId'];
        $token = $param['token'];
        $this->checkMobileToken($userId, $token);

        // 校验客栈是否过期,是否禁用
        $hotelLogic = A('Common/Hotel', 'Logic');
        $result = $hotelLogic->checkHotelActive($hotelId);
        if ($result == false) {
            returnJson(403, 408);
            return;
        }
        $result = $hotelLogic->checkHotelStatus($hotelId);
        if ($result == false) {
            returnJson(403, 401);
            return;
        }

        // 校验是否有操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $hasRight = $adminAuthorityLogic->check($hotelId);
        if (!$hasRight) {
            returnJson(403, 202);
            return;
        }

        // 校验是否已经开通
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        // 保存支付类型
        $hotelPayLogic = A('Common/HotelPay', 'Logic');
        try {
            $hotelPayLogic->savePayType($hotelId, $type);
        } catch (\Exception $e) {
            returnJson($e->getMessage());
            return;
        }

        returnJson(200, 200);
    }

    /**
     * 分享我的客栈链接
     * @modify wenhui 2016-12-08    创建
     */
    public function hotelShareLink() {

        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        // 校验token
        $hotelId = $param['hotel'];
        $userId = $param['userId'];
        $token = $param['token'];
        $this->checkMobileToken($userId, $token);

        //检查操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        if (empty($adminAuthorityLogic->check($hotelId, $userId))) {
            returnJson(403, 202);
            return;
        }

        // 校验是否已经开通
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        // 以选中的客栈标签 作为分享描述
        $hotelDetail = $hotelBookLogic->getInfo($hotelId);
        $description = '';
        foreach ($hotelDetail['specialTag'] as $specialTags) {
            if ($specialTags['enable'] == ENABLE) {
                $description .= $specialTags['name'] . ' ';
            }
        }
        unset($specialTags);

        $hotel = $param['hotel'];
        $hotelName = $hotelDetail['name'];
        $description = trim($description);
        $imageUrls = isset($hotelDetail['logoimageurl']) && !empty($hotelDetail['logoimageurl']) ? MEIZHU_URL . $hotelDetail['logoimageurl'] : '';
        returnJson(200, 200, array(
            'link' => 'http://' . MEIZHU_BOOK_HOST . '/Home/BookPage/index?hotel=' . $hotel . '&l='.LANG_SET,
            'hotelName' => $hotelName,
            'description' => $description,
            'defaultUrl' => MEIZHU_URL . '/Public/uclbrt/image/meizhu.png',
            'imageUrl' => $imageUrls,
        ));
    }

    /**
     * 开通微预定
     * @modify trainyao 2016-04-28    创建
     * @modify wenhui 2016-12-08   添加校验
     * @modify wenhui 2017-05-04 增加国际手机检验
     */
    public function enable() {

        $mobile_version = C('MOBILE_VERSION');
        if($_SERVER['HTTP_V']<$mobile_version['multi_pay_type']){
            returnJson(403, 999);
            return;
        }
        
        $param = I('post.');

        // v2.0.11的参数校验 支持国际号码校验
        $version = getVersion(array('2.0.11'));
        if ($version >= '2.0.11') {
            $validateRule = array(
                'hotel' => 'notnull,notempty,id',
                'userId' => 'notnull,notempty,id',
                'token' => 'notnull,notempty',
                'address' => 'notnull,notempty,nameLength50',
                'contact' => 'notnull,notempty,nameLength20',
                'mobile' => 'notnull,notempty',
                'description' => 'notnull,notempty,nameLength255',
                'orderTimeout' => 'notnull,notempty,orderTimeout',
                'longtitude' => 'notempty,decimal9_6',
                'latitude' => 'notempty,decimal9_6',
                'telephone' => 'notempty,nameLength15',
                'wechat' => 'notempty,nameLength20',
                'hotline' => 'notempty,nameLength15',
            );
            $areaCode = I('post.areaCode', '86', 'string');
            $this->ajaxValidateReturn($this->validateUtil, $param['mobile'], 'globalMobile',
                        array('globalMobile' => array('function', 'checkGlobalMobile,' . $areaCode, '403,130,error'),
                    ));
        } else {
            $validateRule = array(
                'hotel' => 'notnull,notempty,id',
                'userId' => 'notnull,notempty,id',
                'token' => 'notnull,notempty',
                'address' => 'notnull,notempty,nameLength50',
                'contact' => 'notnull,notempty,nameLength20',
                'mobile' => 'notnull,notempty,mobile',
                'description' => 'notnull,notempty,nameLength255',
                'orderTimeout' => 'notnull,notempty,orderTimeout',
                'longtitude' => 'notempty,decimal9_6',
                'latitude' => 'notempty,decimal9_6',
                'telephone' => 'notempty,nameLength15',
                'wechat' => 'notempty,nameLength20',
                'hotline' => 'notempty,nameLength15',
            );
        }

        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        $mobile = $param['mobile'];
        $areaCode = isset($areaCode) ? $areaCode : '86';
        // 校验token
        $userId = $param['userId'];
        $token = $param['token'];
        $this->checkMobileToken($userId, $token);

        //检查操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        if (empty($adminAuthorityLogic->checkIsAdmin($userId))) {
            returnJson(403, 202);
            return;
        }

        // 已开通报错
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $hotelId = $param['hotel'];
        // 校验是否已经开通
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if ($isEnable) {
            returnJson(403, 410);
            return;
        }

        //获取客栈名称
        $hotelEntityModel = D('HotelEntity');
        $hotelEntityInfo = $hotelEntityModel->getInfo($hotelId);
        if(empty($hotelEntityInfo)){
            return ;
        }
        $name = $hotelEntityInfo['name'];
        $enddate = $hotelEntityInfo['enddate'];

        $contact = $param['contact'];
        $address = $param['address'];
        $description = $param['description'];
        $orderTimeout = $param['orderTimeout'];
        $longtitude = $param['longtitude'];
        $latitude = $param['latitude'];
        $telephone = $param['telephone'];
        $wechat = $param['wechat'];
        $hotline = $param['hotline'];

        $enableResult = $hotelBookLogic->enableBook($hotelId, $name, $contact, $mobile, $address, $description, $orderTimeout, $longtitude, $latitude, $telephone, $wechat, $hotline, $enddate, $areaCode);
        if (empty($enableResult)) {
            returnJson(403, 410);
            return;
        }

        returnJson(200, 200);
    }

    /**
     * 校验微预定是否已经申请
     * @modify wenhui 2016-12-08   创建
     */
    public function checkApply() {
        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
        );

        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        // 校验token
        $userId = $param['userId'];
        $token = $param['token'];
        $this->checkMobileToken($userId, $token);

        $hotelId = $param['hotel'];
        //检查操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        if (ACTION_NAME != 'payHistory') {
            $adminAuthorityLogic->check($hotelId, $userId);
        }
        //检查客栈是否已过期
        $hotelLogic = A('Common/Hotel', 'Logic');
        $hotelLogic->checkHotelActive($hotelId);
        $hotelLogic->checkHotelStatus($hotelId);

        // 校验是否已经开通
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $hotelId = $param['hotel'];
        $hotelDetail = $hotelBookLogic->getInfo($hotelId);
        if (empty($hotelDetail)) {
            returnJson(403, 409);
            return;
        }
        if($hotelDetail['enable'] != ENABLE){
            returnJson(403, 409);
            return;
        }
        if($hotelDetail['opened'] != ENABLE){
            returnJson(403, 417);
            return;
        }
        if(time()>strtotime($hotelDetail['enddate'])){
            returnJson(403, 416);
            return;
        }

        returnJson(200, 200);
    }

    /**
     * 获取支付宝或微信 ‘找不到？’ 的链接 根据$type获取不同的链接
     * @modify wenhui 2016-12-09   创建
     */
    public function getLink() {
        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
            'type' => 'notnull,notempty',
        );

        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        // 校验token
        $userId = $param['userId'];
        $token = $param['token'];
        $this->checkMobileToken($userId, $token);

        // 校验是否已经开通
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $hotelId = $param['hotel'];
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }
        // 根据$type获取不同的链接
        $type = $param['type'];
        $data = array();
        switch ($type) {
            case 'ali':
                $data['url'] = 'https://cshall.alipay.com/enterprise/help_detail.htm?help_id=473888';
                break;

            case 'wechatAPPID':
                $data['url'] = MEIZHU_URL . '/Public/dist/Home/image/tips_appid.png';
                break;

            case 'wechatMCHID':
                $data['url'] = MEIZHU_URL . '/Public/dist/Home/image/tips_howtoset.jpg';
                break;

            case 'mpverify':
                $data['url'] = MEIZHU_URL . '/Public/dist/Home/image/tips_mpverify.jpg';
                break;
        }

        returnJson(200, 200, $data);
    }

    /**
     * 保存我的客栈logo
     * @modify wenhui 2017-02-06    创建
     */
    public function saveLogoImage() {
        $param = I('request.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
        );
        $validator = new \Org\Util\Validate();
        $validatePass = $this->ajaxValidateReturn($validator, $param, $validateRule);
        if (empty($validatePass)) {
                return;
        }

        $hotelId = $param['hotel'];
        $userId = $param['userId'];
        $token = $param['token'];
        $config = 'default';

        $this->checkMobileToken($userId, $token);

        //检查操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        if (empty($adminAuthorityLogic->check($hotelId))) {
            returnJson(403, 202);
            return;
        }

        // 判断是否有上传图片
        $uploadedFile = false;
        if (isset($_FILES['file']['tmp_name'])) {
            $uploadedFile = true;

            // 处理上传图片
            $configInfo = C($config);
            $config = array(
                'maxSize' => $configInfo['maxSize'],
                'rootPath' => $configInfo['rootPath'],
                'savePath' => $configInfo['savePath'],
                'exts' => $configInfo['exts'],
                'subName' => array('date', 'Ymd'),
            );
            $upload = new \Think\Upload($config);
            $info = $upload->upload();
            if (!$info) {
                $this->returnJson(500, 511, $upload->getError());
            }
            $filename = '/Uploads/' . $info['file']['savepath'] . $info['file']['savename'];
        }
        $imageUrl = $uploadedFile ? $filename : null;

        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $saveResult = $hotelBookLogic->saveDetail($hotelId, null, null, null, null, null, null, null, null, null, null, null, null, $imageUrl);
        if (empty($saveResult)) {
            return;
        }

        $imageUrl = MEIZHU_URL . $imageUrl;

        returnJson(200, 200, array('imageUrl' => $imageUrl));
    }

    /**
     * 获取客栈logo
     * @modify wenhui 2017-02-06    创建
     */
    public function getLogoImage() {
        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'hotel' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
        );

        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        $hotelId = $param['hotel'];
        $userId = $param['userId'];
        $token = $param['token'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        // 校验是否已经开通
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        $this->checkMobileToken($userId, $token);

        //检查操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        if (empty($adminAuthorityLogic->check($hotelId))) {
            returnJson(403, 202);
            return;
        }

        $hotelDetail = $hotelBookLogic->getInfo($hotelId);

        if (empty($hotelDetail['logoimageurl'])) {
            $logoImageUrl = '';
        } else {
            $logoImageUrl = MEIZHU_URL . $hotelDetail['logoimageurl'];
        }

        returnJson(200, 200, array('imageUrl' => $logoImageUrl));
    }

    public function applyAuth()
    {
        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'hotel' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
        );

        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        $hotelId = $param['hotel'];
        
        $hotelDetailModel = D('HotelDetail');
        $hotelDetail = $hotelDetailModel->getInfoByHotel($hotelId);
        if(empty($hotelDetail)){
            returnJson(403,409);
        }
        
        $hotelAuthModel = D('HotelAuth');
        $hotelAuthInfo = $hotelAuthModel->getInfo($hotelId);
        if(empty($hotelAuthInfo)){
            $data = array(
                'hotelentity_id' => $hotelId,
                'status' => 1,
                'hotelname' => $hotelDetail['name'],
                'contact' => $hotelDetail['contact'],
                'telephone' => $hotelDetail['mobile'],
                'address' => $hotelDetail['address']
            );
            $hotelAuthModel->add($data);
        }else {
            $where = array(
                'hotelentity_id' => $hotelId
            );
            $data = array(
                'status' => 1,
                'hotelname' => $hotelDetail['name'],
                'contact' => $hotelDetail['contact'],
                'telephone' => $hotelDetail['mobile'],
                'address' => $hotelDetail['address']
            );
            $hotelAuthModel->where($where)->save($data);
        }
        returnJson(200,200);        
    }
    public function cancelAuth()
    {
        $hotelId = $param['hotel'];
        $hotelAuthModel = D('HotelAuth');
        $hotelAuthInfo = $hotelAuthModel->getInfo($hotelId);
        if(!empty($hotelAuthInfo) && $hotelAuthInfo['status']=='1'){
            $where = array(
                'hotelentity_id' => $hotelId
            );
            $data = array(
                'status' => 0
            );
            $hotelAuthModel->where($where)->save($data);
        }
        returnJson(200,200); 
	}

     /**
     * 保存小黑包板内容
     * @modify wenhui 2017-07-28    创建
     */
    public function saveBlackboard() {
        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
            'hotel' => 'notnull,notempty,id',
            'blackBoardContent' => 'notnull,nameLength500',
        );
        $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);

        $userId = $param['userId'];
        $token = $param['token'];
        $hotelId = $param['hotel'];
        $blackBoardContent = $param['blackBoardContent'];

        //检查token
        $this->checkMobileToken($userId, $token);

        $hotelLogic = A('Common/Hotel', 'Logic');
        $result = $hotelLogic->saveHotelBlackboard($hotelId, $blackBoardContent);

        returnJson(200, 200);
    }

    /**
     * 获取小黑包板内容
     * @modify wenhui 2017-07-28    创建
     */
    public function getBlackboard() {
        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
            'hotel' => 'notnull,notempty,id',
        );
        $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);

        $userId = $param['userId'];
        $token = $param['token'];
        $hotelId = $param['hotel'];

        //检查token
        $this->checkMobileToken($userId, $token);

        $hotelLogic = A('Common/Hotel', 'Logic');
        $blackData = $hotelLogic->getHotelBlackboard($hotelId);

        returnJson(200, 200, $blackData);
    }

    /**
     * 获提醒内容
     * @modify wenhui 2017-07-28    创建
     */
    public function getRemindList() {
        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
            'hotel' => 'notnull,notempty',
            'currentPage' => 'notnull,notempty',
            'pageSize' => 'notnull,notempty',
        );
        $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);

        $userId = $param['userId'];
        $token = $param['token'];
        $hotelId = json_decode(stripcslashes(htmlspecialchars_decode($param['hotel'])), true);

        //检查token
        $this->checkMobileToken($userId, $token);

        $currentPage = isset($param['currentPage']) ? $param['currentPage'] : 1;
        $pageSize = isset($param['pageSize']) ? $param['pageSize'] : 15;
        $keys = isset($param['keys']) && !empty($param['keys']) ? $param['keys'] : null;
        $reminded = isset($param['remind']) && !empty($param['remind']) ? $param['remind'] : null;
        $newstype = isset($param['newstype']) && !empty($param['newstype']) ? $param['newstype'] : null;

        $hotelLogic = A('Common/Hotel', 'Logic');
        foreach ($hotelId as $key => $hotel) {
            // 检查客栈app是否开通
            $enableResult = $hotelLogic->checkHotelAppEnable($hotel);
            if ($enableResult == false) {
                unset($hotelId[$key]);
                continue;
            }
        }
        unset($hotel);

        if (empty($hotelId)) {
            returnJson(403, 800, 'error');
        }
        $remindList = $hotelLogic->getRemindList($hotelId, $currentPage, $pageSize, $keys, $reminded, $newstype);
        if (empty($remindList) || empty($remindList['remindList'])) {
            returnJson(403, 800, 'error');
        }

        returnJson(200, 200, $remindList);
    }

    /**
     * 保存闹钟提醒数据
     * @modify wenhui 2017-07-28    创建
     */
    public function saveRemind() {
        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
            'hotel' => 'notnull,notempty,id',
            'remindDate' => 'notnull,notempty',
            'content' => 'notnull,notempty,nameLength60',
        );
        // 删除 不检查 remindDate content
        if (isset($param['dropRemind']) || isset($param['isRead'])) {
            unset($validateRule['remindDate']);
            unset($validateRule['content']);
        }

        $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);

        $userId = $param['userId'];
        $token = $param['token'];

        //检查token
        $this->checkMobileToken($userId, $token);

        $hotelId = $param['hotel'];
        $remindDate = isset($param['remindDate']) ? $param['remindDate'] : '';
        $content = $param['content'];
        $isRead = isset($param['isRead']) ? $param['isRead'] : null;
        $alarmClockId = isset($param['alarmClockId']) && !empty($param['alarmClockId']) ? $param['alarmClockId'] : null;
        $dropRemind = isset($param['dropRemind']) ? $param['dropRemind'] : null;

        $hotelLogic = A('Common/Hotel', 'Logic');
        $saveResult = $hotelLogic->saveRemind($hotelId, $remindDate, $content, $alarmClockId, $dropRemind, $isRead);

        returnJson(200, 200);
    }

    /**
     * 获取记一笔记录
     * @modify wenhui 2017-12-19 创建
     */
    public function getNoteCost() {
        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
            'hotel' => 'notnull,notempty,id',
            'start' => 'notnull,notempty,isDate',
            'end' => 'notnull,notempty,isDate',
        );
        $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);

        $userId = $param['userId'];
        $token = $param['token'];
        $hotelId = $param['hotel'];
        $type = isset($param['type']) ? $param['type'] : null; // 1=收入 2=支出 null=全部
        $startDate = $param['start'];
        $endDate = $param['end'];
        $pageIndex = isset($param['current']) ? $param['current'] : 1;

        //检查token
        $this->checkMobileToken($userId, $token);

        // 检查操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $adminAuthorityLogic->check($hotelId);

        $reportLogic = A('Common/Report', 'Logic');
        $accountData = $reportLogic->getHotelAccountView($hotelId, $type, $startDate, $endDate, $pageIndex);

        if (is_null($type)) {
            $returnData = array(
                'income' => $accountData['income'],
                'outcome' => $accountData['outcome'],
                'surplus' => $accountData['income'] - $accountData['outcome'],
            );
        } else {
            $returnData = array(
                'income' => $accountData['income'],
                'outcome' => $accountData['outcome'],
                'surplus' => $accountData['income'] - $accountData['outcome'],
                'account' => $accountData['info'],
                'total' => $accountData['itemtotal'],
                'pages' => $accountData['pagetotal'],
                'currentPage' => $accountData['current'],
            );
        }

        returnJson(200, 200, $returnData);
    }

    /**
     * 添加记一笔记录
     * @modify wenhui 2017-12-19 创建
     */
    public function addNoteCost() {
        $param = I('post.');

        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
            'hotel' => 'notnull,notempty,id',
            'noteId' => 'notnull,notempty,id',
            'payId' => 'notnull,notempty,id',
            'type' => 'notnull,notempty,id',
            'price' => 'notnull,notempty,decimal8_2',
            'noteDate' => 'notnull,notempty,isDate',
            'remark' => 'nameLength100',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        $userId = $param['userId'];
        $token = $param['token'];
        $hotelId = $param['hotel'];
        $noteId = $param['noteId'];
        $payId = $param['payId'];
        $type = $param['type']; // 1=收入 2=支出
        $price = $param['price'];
        $noteDate = $param['noteDate'];
        $remark = $param['remark'];

        //检查token
        $this->checkMobileToken($userId, $token);

        // 检查操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $adminAuthorityLogic->check($hotelId);

        $hotelLogic = A('Common/Hotel', 'Logic');

        $addResult = $hotelLogic->addNoteCost($hotelId, $noteId, $payId, $type, $price, $noteDate, $remark);

        returnJson(200, 200);
    }

    /**
     * 编辑记一笔记录
     * @modify wenhui 2017-12-19 创建
     */
    public function editNoteCost() {
        $param = I('post.');

        $isDelete = isset($param['delete']) && $param['delete'] == 'delete' ? true : null;
        if (is_null($isDelete)) {
            $validateRule = array(
                'userId' => 'notnull,notempty,id',
                'token' => 'notnull,notempty',
                'hotel' => 'notnull,notempty,id',
                'noteCostId' => 'notnull,notempty,id',
                'noteId' => 'notnull,notempty,id',
                'payId' => 'notnull,notempty,id',
                'type' => 'notnull,notempty,id',
                'price' => 'notnull,notempty,decimal8_2',
                'noteDate' => 'notnull,notempty,isDate',
                'remark' => 'nameLength100',
            );
        } else {
            $validateRule = array(
                'userId' => 'notnull,notempty,id',
                'token' => 'notnull,notempty',
                'hotel' => 'notnull,notempty,id',
                'noteCostId' => 'notnull,notempty,id',
            );
        }

        $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);

        $userId = $param['userId'];
        $token = $param['token'];
        $hotelId = $param['hotel'];
        $noteCostId = $param['noteCostId'];
        $noteId = isset($param['noteId']) ? $param['noteId'] : null;
        $payId = isset($param['payId']) ? $param['payId'] :mull;
        $type = isset($param['type']) ? $param['type'] : null; // 1=收入 2=支出
        $price = isset($param['price']) ? $param['price'] : null;
        $noteDate = isset($param['noteDate']) ? $param['noteDate'] : null;
        $remark = isset($param['remark']) ? $param['remark'] : null;

        //检查token
        $this->checkMobileToken($userId, $token);

        // 检查操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $adminAuthorityLogic->check($hotelId);

        $noteName = $param['name'];
        $hotelLogic = A('Common/Hotel', 'Logic');
        $addResult = $hotelLogic->editNoteCost($hotelId, $noteCostId, $noteId, $payId, $type, $price, $noteDate, $remark, $isDelete);

        // 返回数据
       /* $data = $hotelLogic->getNoteCost($hotelId, $noteCostId);
        $data = !empty($data) ? $data[0] : [];*/

        returnJson(200, 200);
    }
}
